package com.sunlands.deskmate.channel;

import com.sunlands.deskmate.constant.YN;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;

/**
 * 每个接入netty的用户的唯一信息
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ChannelInfo implements Serializable {
    private static final long serialVersionUID = 1235322837029595677L;
    /**
     * 学员或者销售都可以使用此字段
     */

    private Long userId;
    private long createTime;
    /**
     * 是否在前台运行，1、是 0、不是
     */
    private Integer topRun;
    private Long workId;

    /**
     * 切到后台时间--（后台运行开始时间）
     */
    private Long backRunTime;

    public static ChannelInfo parseSessionKey(String sessionKey) {
        String[] keyArr = sessionKey.split("_");
        return new ChannelInfo(Long.parseLong(keyArr[1]));
    }

    public ChannelInfo(Long userId) {
        this.topRun = YN.Y.code;
        this.userId = userId;
    }

    public String getSessionKey() {
        return String.format("user_%s", userId);
    }

}
